Skip to content

Conversation

@andrey-churkin
Copy link
Contributor

@andrey-churkin andrey-churkin commented Mar 25, 2025

Changes

Apply the eliminate_nop_cast optimization pass before building the NNCF graph. This pass aims to eliminate no-op cast nodes in the graph. A no-op cast is a cast that doesn't change the value, such as casting a tensor to its own type.

Reason for changes

Statistics cannot be collected after the no-op Cast nodes because such nodes are removed from the ONNX inference graph during the session.

Related tickets

Ref: 164211

@andrey-churkin andrey-churkin requested a review from a team as a code owner March 25, 2025 09:30
@github-actions github-actions bot added the NNCF ONNX Pull requests that updates NNCF ONNX label Mar 25, 2025
@andrey-churkin
Copy link
Contributor Author

@kshpv Please review

@andrey-churkin andrey-churkin force-pushed the ac/eliminate_nop_cast branch from 4650dc4 to fa04951 Compare April 3, 2025 18:20
@andrey-churkin andrey-churkin requested a review from alexsu52 April 3, 2025 18:21
@alexsu52 alexsu52 removed the request for review from kshpv April 20, 2025 17:06
@alexsu52 alexsu52 self-assigned this Apr 20, 2025
Copy link

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR in draft or can it be reviewed?

@andrey-churkin andrey-churkin force-pushed the ac/eliminate_nop_cast branch from 76053b7 to ac7b3c2 Compare April 30, 2025 12:54
@andrey-churkin andrey-churkin marked this pull request as draft April 30, 2025 12:54
@andrey-churkin andrey-churkin force-pushed the ac/eliminate_nop_cast branch from f059315 to 17f658e Compare May 1, 2025 08:33
@andrey-churkin andrey-churkin marked this pull request as ready for review May 1, 2025 10:38
@alexsu52 alexsu52 requested a review from anzr299 May 1, 2025 12:09
@andrey-churkin
Copy link
Contributor Author

NNCF/nightly/e2e_onnx_model_zoo: Build # 953

@andrey-churkin
Copy link
Contributor Author

Is this PR in draft or can it be reviewed?

I've updated it, so it can now be reviewed.

@andrey-churkin andrey-churkin requested a review from alexsu52 May 1, 2025 12:13
@alexsu52 alexsu52 requested review from Copilot and removed request for alexsu52 May 2, 2025 06:39
Copy link

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces the eliminate_nop_cast optimization pass to remove no-op cast nodes from ONNX graphs before quantization. Key changes include:

  • Adding a new pass in nncf/onnx/graph/passes.py to eliminate redundant Cast nodes.
  • Integrating the pass into model preprocessing in both the test and quantization flows.
  • Creating a test model with a no-op Cast and a corresponding unit test in tests/onnx.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/onnx/test_passes.py Added a unit test to validate the elimination of no-op Cast nodes.
tests/onnx/models.py Introduced a helper to build a MatMul model with a no-op Cast node.
nncf/onnx/quantization/quantize_model.py Integrated preprocess passes into the quantization pipeline.
nncf/onnx/graph/passes.py Implemented the eliminate_nop_cast and apply_preprocess_passes passes.
Comments suppressed due to low confidence (2)

nncf/onnx/graph/passes.py:58

  • Consider verifying that cast_node.output[0] exists in model.graph.value_info before attempting removal, to prevent potential KeyError if the value info is absent.
model.graph.value_info.remove(value_infos[cast_node.output[0]])

tests/onnx/models.py:1911

  • Ensure that numpy is imported as 'np' in this module if it is not already imported to avoid a NameError.
W_values = np.random.rand(3, 2).astype(np.float32)

@andrey-churkin andrey-churkin requested a review from anzr299 May 2, 2025 08:04
@alexsu52 alexsu52 merged commit c72f787 into openvinotoolkit:develop May 2, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NNCF ONNX Pull requests that updates NNCF ONNX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants